package org.lanqiao.api.product;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.ProductPOJO;
import org.lanqiao.service.ProductServiceImpl;

/**
 * Servlet implementation class CancelProductServlet
 */
@WebServlet("/api/product/cancelproduct")
public class CancelProductServlet extends HttpServlet {
	
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//下架商品 前台传入的数据名productId  api  /api/product/cancelproduct 返回商品所有信息
		ProductPOJO product=new ProductPOJO();
		
		product.setProductId(request.getParameter("productId"));
	
		JsonResult result=null;
		try {
			ProductServiceImpl productService=new ProductServiceImpl();
			List<LinkedHashMap<String, Object>> list=productService.cancelProductService(product);
			if(list.size()>0) {
				result=new JsonResult("下架成功",Constants.STATUS_SUCCESS,list);
			}else {
				result=new JsonResult("下架失败",Constants.STATUS_UNFOUND);
			}
		}catch(Exception e){
			result=new JsonResult("下架异常",Constants.STATUS_FAILURE);
		}
		JsonResultWriter.writer(response,result);
	}
	

}
